#include "TryFinally.h"
#include "IVisitor.h"

TryFinally::TryFinally(const StmtTypeList& body, const suiteTypePtr& finalbody, int nodeId):
    stmtType(nodeId),
    _body(body),
    _finalbody(finalbody)
{
}
    
TryFinally::~TryFinally()
{
    _body.clear();
}
    
QString TryFinally::type() const
{
    return "TryFinally";
}
    

StmtTypeList TryFinally::body()
{
    return _body;
}

void TryFinally::setBody(const StmtTypeList& body)
{
    _body = body;
}

suiteTypePtr TryFinally::finalbody()
{
    return _finalbody;
}

void TryFinally::setFinalbody(const suiteTypePtr& finalbody)
{
    _finalbody = finalbody;
}

    
QString TryFinally::toString() const
{
    return QString("TryFinally[body=%1, finalbody=%2]").
                arg(_body.toString()).
                arg(_finalbody ? _finalbody->toString():"");
}
    
void TryFinally::accept(IVisitor* visitor, const SimpleNodePtr& node)
{
    visitor->visitTryFinally(node.dynamicCast<TryFinally>());
}
    
void TryFinally::traverse(IVisitor* visitor)
{
    _body.traverse(visitor);
    if (_finalbody != NULL)
        _finalbody->accept(visitor, _finalbody);
}